﻿@{
    ViewBag.Title = "AddArticleRelation";
}

@model Pagination<CW_Article>
<h3>菜单[@ViewBag.MenuName] -- 添加文章</h3>
<div class="row">
    <div class="col-lg-8">
        @using (Html.BeginForm("AddArticleRelation", "Admin", FormMethod.Get))
        {
            <input type="hidden" name="mid" value="@Request.QueryString["mid"]" />
            <input type="text" class="form-control" style="width:200px;display:inline-block;" name="keyword" value="@ViewBag.keyword" />
            <input type="submit" class="btn btn-default" value="搜索" />
            @Html.ActionLink("返回列表", "MenuArticleRelation", new { mid = @Request.QueryString["mid"] }, new { @class = "btn btn-default" })
        }
    </div>
</div>
<hr />
<div>
    <table class="table table-bordered table-condensed">
        <thead>
            <tr>   
                <td>logo</td>             
                <td>标题</td>
                <td>简介</td>
                <td>时间</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        <img alt="@item.Title" height="50" src="@Url.Content("~/images/logo/"+item.Thumb)" />
                    </td>
                    <td>@item.Title</td>
                    <td>
                        @item.Abstract          
                    </td>
                    <td>@item.CreateDate</td>
                    <td>
                        <input type="button" onclick="addRelate(@item.ArticleId,@Request.QueryString["mid"],this)" class="btn btn-default" value="添加" />
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>

@if (Model.TotalPages > 0)
{
    <nav>
        <ul class="pagination">
            <li>
                @Html.ActionLink("<<", "AddArticleRelation", new { page = 0, keyword = ViewBag.keyword })
            </li>
            @for (int i = 0; i < Model.TotalPages; i++)
            {
                if (i == Model.PageIndex)
                {
                    <li class="active">
                        @Html.ActionLink((i + 1).ToString(), "AddArticleRelation", new { page = i, keyword = ViewBag.keyword })
                    </li>
                }
                else
                {
                    <li>
                        @Html.ActionLink((i + 1).ToString(), "AddArticleRelation", new { page = i, keyword = ViewBag.keyword })
                    </li>
                }
            }
            <li>
                @Html.ActionLink(">>", "AddArticleRelation", new { page = Model.TotalPages - 1 > 0 ? Model.TotalPages - 1 : 0, keyword = ViewBag.keyword })
            </li>
        </ul>
    </nav>
}
@section Scripts {
    <script>
        function addRelate(articleid, mid, obj) {
            $(obj).attr("disabled", "disabled");
            var param = {
                articleid: articleid,
                mid: mid
            }
            $.ajax({
                type: "POST",
                url: "@Url.Action("AddRelation")",
                dataType: "json",
                data: param,
                success: function (result) {
                    if (result == "success") {
                        $(obj).closest("tr").remove();
                    }
                }
            });
        }
    </script>
}
